﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using br.com.SistemaChamados;
using br.com.SistemaChamados.Controller;
using br.com.SistemaChamados.Model;
using br.com.SistemaChamados.Enum;

public partial class Pages_PlaceMain : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void gvPlaces_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        PlaceController placeController = new PlaceController();
        Place place = new Place();
        try
        {
            int id = Convert.ToInt32(e.CommandArgument);
            switch (e.CommandName)
            {
                case "ExcludeData":
                    place.Id = id;
                    if (placeController.DeletePlace(place) == EnumGenericState.GENERIC_STATE_SUCCESS)
                    {
                        Response.Write(@"<script language='javascript'>alert('Local excluído com sucesso!');</script>");
                        Response.Redirect("PlaceMain.aspx");
                    }
                    else
                    {
                        Response.Write(@"<script language='javascript'>alert('Ocorreu um erro durante a exclusão, por favor tente novamente!');</script>");
                    }
                    break;

                case "UpdateData":
                    Session["PlaceIdToUpdate"] = id;
                    Response.Redirect("PlaceUpdate.aspx");
                    break;
            }
        }
        catch (Exception ex)
        {
            Response.Write(@"<script language='javascript'>alert('Ocorreu um erro ao deletar o local: <br>" + ex.Message + ".');</script>");
            place = null;
            placeController = null;
        }
    }
}